#include <algorithm>
#include <iostream>
#include <vector>
#define ll long long;
#define N 100010
#define endl '\n'
using namespace std;
int n;
int arr[N];

void solve()
{
    cin>>n;
    for(int i = 1;i<=n;++i)
    {
        cin>>arr[i];
    }
    vector<int> tail;
    //tail.push_back(arr[1]);
    for(int i = 1;i<=n;++i)
    {
        int num = arr[i];
        int pos = lower_bound(tail.begin(), tail.end(),num)-tail.begin();
        if(pos == tail.size())
        {
            tail.push_back(num);
        }
        else
        {
            tail[pos] = num;
        }
    }
        cout<<tail.size()<<endl;
    
    
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    solve();
    return 0;
}
